package com.micromap.dataprocessing.service.impl

import com.micromap.dataprocessing.repository.BaseRepository
import com.micromap.dataprocessing.service.BaseService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Example

open class BaseServiceImpl<T, out D : BaseRepository<T>>(@Autowired protected val baseRepository: D) : BaseService<T> {
    override fun findAll(): List<T> = baseRepository.findAll()

    override fun findAll(example: Example<T>): List<T> = baseRepository.findAll(example)

    override fun save(record: T): T = baseRepository.save(record)

    override fun findOne(id: Long?): T = baseRepository.findOne(id)

    override fun exists(id: Long?): Boolean = baseRepository.exists(id)

    override fun delete(id: Long?) = baseRepository.delete(id)

    override fun delete(record: T) = baseRepository.delete(record)

    override fun delete(ids: List<Long>) = baseRepository.delete(baseRepository.findAll(ids))

    override fun save(records: List<T>): List<T> = baseRepository.save(records)
}